import pygame
from random import *
import time
import bullet


class SmallEnemy(pygame.sprite.Sprite):  # 一级敌人 继承自精灵类
    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)

        # self.image1 = pygame.image.load("images/enemy1.png").convert_alpha()  # 加载一级敌人图像
        # self.image1 = pygame.image.load("images/enemy11_level1.png").convert_alpha()  # 加载一级敌人图像
        self.image1 = pygame.image.load("images/enemy_level1.png").convert_alpha()  # 加载一级敌人图像
        self.destroy_images = []
        self.destroy_images.extend([ \
            pygame.image.load("images/destroy_1.png").convert_alpha(), \
            pygame.image.load("images/destroy_2.png").convert_alpha(), \
            pygame.image.load("images/destroy_3.png").convert_alpha(), \
            pygame.image.load("images/destroy_4.png").convert_alpha(), \
            pygame.image.load("images/destroy_5.png").convert_alpha(), \
            pygame.image.load("images/destroy_6.png").convert_alpha(), \
            pygame.image.load("images/destroy_7.png").convert_alpha(), \
            pygame.image.load("images/destroy_8.png").convert_alpha(), \
            ])  # 加载一级敌人摧毁图像1 2 3 4
        self.rect = self.image1.get_rect()  # 或者图像大小
        self.width, self.height = bg_size[0], bg_size[1]  # 获取敌人大小
        self.speed = 2
        self.active = True  # 激活
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-5 * self.height, 0)  # 规定敌人生成位置 随机生成
        self.mask = pygame.mask.from_surface(self.image1)

    def move(self):  # 移动
        if self.rect.top < self.height:  # 在边界之内
            self.rect.top += self.speed  # 下移动
        else:
            self.reset()  # 否则重置敌人位置

    def reset(self):  # 重置敌人位置
        self.active = True
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-5 * self.height, 0)  # 重新 随机生成


class MidEnemy(pygame.sprite.Sprite):  # 二级敌人类 与上同理
    energy = 5  # 血量

    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)

        self.image1 = pygame.image.load("images/enemy_level2.png").convert_alpha()
        # self.image_hit = pygame.image.load("images/enemy2_hit.png").convert_alpha()  # 击中图像
        self.destroy_images = []
        self.destroy_images.extend([ \
            pygame.image.load("images/destroy_1.png").convert_alpha(), \
            pygame.image.load("images/destroy_2.png").convert_alpha(), \
            pygame.image.load("images/destroy_3.png").convert_alpha(), \
            pygame.image.load("images/destroy_4.png").convert_alpha(), \
            pygame.image.load("images/destroy_5.png").convert_alpha(), \
            pygame.image.load("images/destroy_6.png").convert_alpha(), \
            pygame.image.load("images/destroy_7.png").convert_alpha(), \
            pygame.image.load("images/destroy_8.png").convert_alpha(), \
            ])  # 摧毁图像
        self.rect = self.image1.get_rect()
        self.width, self.height = bg_size[0], bg_size[1]
        self.speed = 1
        self.active = True
        self.hit = False
        self.energy = MidEnemy.energy
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-5 * self.height, -self.height)
        self.mask = pygame.mask.from_surface(self.image1)

    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.reset()

    def reset(self):
        self.active = True
        self.energy = MidEnemy.energy
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-8 * self.height, -self.height)


class BigEnemy(pygame.sprite.Sprite):  # 三级敌人
    energy = 10  # 血量

    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)

        self.image1 = pygame.image.load("images/enemy3_n1.png").convert_alpha()  # 飞行图像1
        self.image2 = pygame.image.load("images/enemy3_n2.png").convert_alpha()  # 飞行图形2
        # self.image_hit = pygame.image.load("images/enemy3_hit.png").convert_alpha()  # 击中图像
        self.destroy_images = []
        self.destroy_images.extend([ \
            pygame.image.load("images/destroy_1.png").convert_alpha(), \
            pygame.image.load("images/destroy_2.png").convert_alpha(), \
            pygame.image.load("images/destroy_3.png").convert_alpha(), \
            pygame.image.load("images/destroy_4.png").convert_alpha(), \
            pygame.image.load("images/destroy_5.png").convert_alpha(), \
            pygame.image.load("images/destroy_6.png").convert_alpha(), \
            pygame.image.load("images/destroy_7.png").convert_alpha(), \
            pygame.image.load("images/destroy_8.png").convert_alpha(), \
            ])  # 摧毁图像
        self.rect = self.image1.get_rect()
        self.width, self.height = bg_size[0], bg_size[1]
        self.speed = 1
        self.active = True
        self.hit = False
        self.energy = BigEnemy.energy
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-10 * self.height, -5 * self.height)
        self.mask = pygame.mask.from_surface(self.image1)

    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.reset()

    def reset(self):
        self.energy = BigEnemy.energy
        self.active = True
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-10 * self.height, -5 * self.height)

class boss0(pygame.sprite.Sprite):  # 四级敌人
    energy = 15  # 血量

    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)

        self.image1 = pygame.image.load("images/boss0.png").convert_alpha()  # 飞行图像1
        # self.image2 = pygame.image.load("images/enemy3_n2.png").convert_alpha()  # 飞行图形2
        # self.image_hit = pygame.image.load("images/enemy3_hit.png").convert_alpha()  # 击中图像
        self.destroy_images = []
        self.destroy_images.extend([ \
            pygame.image.load("images/destroy_1.png").convert_alpha(), \
            pygame.image.load("images/destroy_2.png").convert_alpha(), \
            pygame.image.load("images/destroy_3.png").convert_alpha(), \
            pygame.image.load("images/destroy_4.png").convert_alpha(), \
            pygame.image.load("images/destroy_5.png").convert_alpha(), \
            pygame.image.load("images/destroy_6.png").convert_alpha(), \
            pygame.image.load("images/destroy_7.png").convert_alpha(), \
            pygame.image.load("images/destroy_8.png").convert_alpha(), \
            ])  # 摧毁图像
        self.rect = self.image1.get_rect()
        self.width, self.height = bg_size[0], bg_size[1]
        self.speed = 1
        self.active = True
        self.hit = False
        self.energy = boss0.energy
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-10 * self.height, -5 * self.height)
        self.mask = pygame.mask.from_surface(self.image1)

    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.reset()

    def reset(self):
        self.energy = BigEnemy.energy
        self.active = True
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-10 * self.height, -5 * self.height)

class boss1(pygame.sprite.Sprite):  # 五级敌人
    energy = 20  # 血量

    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)

        self.image1 = pygame.image.load("images/boss1.png").convert_alpha()  # 飞行图像1
        # self.image2 = pygame.image.load("images/enemy3_n2.png").convert_alpha()  # 飞行图形2
        # self.image_hit = pygame.image.load("images/enemy3_hit.png").convert_alpha()  # 击中图像
        self.destroy_images = []
        self.destroy_images.extend([ \
            pygame.image.load("images/destroy_1.png").convert_alpha(), \
            pygame.image.load("images/destroy_2.png").convert_alpha(), \
            pygame.image.load("images/destroy_3.png").convert_alpha(), \
            pygame.image.load("images/destroy_4.png").convert_alpha(), \
            pygame.image.load("images/destroy_5.png").convert_alpha(), \
            pygame.image.load("images/destroy_6.png").convert_alpha(), \
            pygame.image.load("images/destroy_7.png").convert_alpha(), \
            pygame.image.load("images/destroy_8.png").convert_alpha(), \
            ])  # 摧毁图像
        self.rect = self.image1.get_rect()
        self.width, self.height = bg_size[0], bg_size[1]
        self.speed = 1
        self.active = True
        self.hit = False
        self.energy = boss1.energy
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-10 * self.height, -5 * self.height)
        self.mask = pygame.mask.from_surface(self.image1)

    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.reset()

    def reset(self):
        self.energy = BigEnemy.energy
        self.active = True
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-10 * self.height, -5 * self.height)

class boss2(pygame.sprite.Sprite):  # 六级敌人
    energy = 22  # 血量

    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)

        self.image1 = pygame.image.load("images/boss2.png").convert_alpha()  # 飞行图像1
        # self.image2 = pygame.image.load("images/enemy3_n2.png").convert_alpha()  # 飞行图形2
        # self.image_hit = pygame.image.load("images/enemy3_hit.png").convert_alpha()  # 击中图像
        self.destroy_images = []
        self.destroy_images.extend([ \
            pygame.image.load("images/destroy_1.png").convert_alpha(), \
            pygame.image.load("images/destroy_2.png").convert_alpha(), \
            pygame.image.load("images/destroy_3.png").convert_alpha(), \
            pygame.image.load("images/destroy_4.png").convert_alpha(), \
            pygame.image.load("images/destroy_5.png").convert_alpha(), \
            pygame.image.load("images/destroy_6.png").convert_alpha(), \
            pygame.image.load("images/destroy_7.png").convert_alpha(), \
            pygame.image.load("images/destroy_8.png").convert_alpha(), \
            ])  # 摧毁图像
        self.rect = self.image1.get_rect()
        self.width, self.height = bg_size[0], bg_size[1]
        self.speed = 1
        self.active = True
        self.hit = False
        self.energy = boss2.energy
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-10 * self.height, -5 * self.height)
        self.mask = pygame.mask.from_surface(self.image1)

    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.reset()

    def reset(self):
        self.energy = BigEnemy.energy
        self.active = True
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-10 * self.height, -5 * self.height)
class boss3(pygame.sprite.Sprite):  #七级敌人
    energy = 24  # 血量

    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)

        self.image1 = pygame.image.load("images/boss3.png").convert_alpha()  # 飞行图像1
        # self.image2 = pygame.image.load("images/enemy3_n2.png").convert_alpha()  # 飞行图形2
        # self.image_hit = pygame.image.load("images/enemy3_hit.png").convert_alpha()  # 击中图像
        self.destroy_images = []
        self.destroy_images.extend([ \
            pygame.image.load("images/destroy_1.png").convert_alpha(), \
            pygame.image.load("images/destroy_2.png").convert_alpha(), \
            pygame.image.load("images/destroy_3.png").convert_alpha(), \
            pygame.image.load("images/destroy_4.png").convert_alpha(), \
            pygame.image.load("images/destroy_5.png").convert_alpha(), \
            pygame.image.load("images/destroy_6.png").convert_alpha(), \
            pygame.image.load("images/destroy_7.png").convert_alpha(), \
            pygame.image.load("images/destroy_8.png").convert_alpha(), \
            ])  # 摧毁图像
        self.rect = self.image1.get_rect()
        self.width, self.height = bg_size[0], bg_size[1]
        self.speed = 1
        self.active = True
        self.hit = False
        self.energy = boss3.energy
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-10 * self.height, -5 * self.height)
        self.mask = pygame.mask.from_surface(self.image1)

    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.reset()

    def reset(self):
        self.energy = BigEnemy.energy
        self.active = True
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-10 * self.height, -5 * self.height)
class boss4(pygame.sprite.Sprite):  # 四级敌人
    energy = 26  # 血量

    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)

        self.image1 = pygame.image.load("images/boss4.png").convert_alpha()  # 飞行图像1
        # self.image2 = pygame.image.load("images/enemy3_n2.png").convert_alpha()  # 飞行图形2
        # self.image_hit = pygame.image.load("images/enemy3_hit.png").convert_alpha()  # 击中图像
        self.destroy_images = []
        self.destroy_images.extend([ \
            pygame.image.load("images/destroy_1.png").convert_alpha(), \
            pygame.image.load("images/destroy_2.png").convert_alpha(), \
            pygame.image.load("images/destroy_3.png").convert_alpha(), \
            pygame.image.load("images/destroy_4.png").convert_alpha(), \
            pygame.image.load("images/destroy_5.png").convert_alpha(), \
            pygame.image.load("images/destroy_6.png").convert_alpha(), \
            pygame.image.load("images/destroy_7.png").convert_alpha(), \
            pygame.image.load("images/destroy_8.png").convert_alpha(), \
            ])  # 摧毁图像
        self.rect = self.image1.get_rect()
        self.width, self.height = bg_size[0], bg_size[1]
        self.speed = 1
        self.active = True
        self.hit = False
        self.energy = boss4.energy
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-10 * self.height, -5 * self.height)
        self.mask = pygame.mask.from_surface(self.image1)

    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.reset()

    def reset(self):
        self.energy = BigEnemy.energy
        self.active = True
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-10 * self.height, -5 * self.height)
class boss5(pygame.sprite.Sprite):  # 四级敌人
    energy = 28  # 血量

    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)

        self.image1 = pygame.image.load("images/boss5.png").convert_alpha()  # 飞行图像1
        # self.image2 = pygame.image.load("images/enemy3_n2.png").convert_alpha()  # 飞行图形2
        # self.image_hit = pygame.image.load("images/enemy3_hit.png").convert_alpha()  # 击中图像
        self.destroy_images = []
        self.destroy_images.extend([ \
            pygame.image.load("images/destroy_1.png").convert_alpha(), \
            pygame.image.load("images/destroy_2.png").convert_alpha(), \
            pygame.image.load("images/destroy_3.png").convert_alpha(), \
            pygame.image.load("images/destroy_4.png").convert_alpha(), \
            pygame.image.load("images/destroy_5.png").convert_alpha(), \
            pygame.image.load("images/destroy_6.png").convert_alpha(), \
            pygame.image.load("images/destroy_7.png").convert_alpha(), \
            pygame.image.load("images/destroy_8.png").convert_alpha(), \
            ])  # 摧毁图像
        self.rect = self.image1.get_rect()
        self.width, self.height = bg_size[0], bg_size[1]
        self.speed = 1
        self.active = True
        self.hit = False
        self.energy = boss0.energy
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-10 * self.height, -5 * self.height)
        self.mask = pygame.mask.from_surface(self.image1)

    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.reset()

    def reset(self):
        self.energy = BigEnemy.energy
        self.active = True
        self.rect.left, self.rect.top = \
            randint(0, self.width - self.rect.width), \
            randint(-10 * self.height, -5 * self.height)

